/*
 * Verhältnis Treffer/Fehltreffer
 *   -> Word-Stats auswerten
 */
package complet.app.tool.experiment;

import complet.helper.IOHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class experiment4 {

    private static BufferedReader ws = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\WordStat_1.log");
    private static BufferedWriter out1 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\experiment4\\words1.dat");
    private static TreeMap<String, Integer> tm_r = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm_f = new TreeMap<String, Integer>();
    private static TreeMap<String, Double> tm = new TreeMap<String, Double>();
    private static TreeMap<String, Double> tm_o = null;
    private static final Comparator<String> COMP = new Comparator<String>() {

        public int compare(String s1, String s2) {
            if (tm.get(s1) > tm.get(s2)) {
                return -1;
            }
            return 1;
        }
    };

    public static void main(String[] args) {
        try {
            tm_o = new TreeMap<String, Double>(COMP);
            String strLine;
            String[] line;
            while (true && (strLine = ws.readLine()) != null) {
                line = strLine.split("\t");
                int r = Integer.parseInt(line[1]);
                int f = Integer.parseInt(line[2]);
                if (f > 0) {
                    tm_r.put(line[0], r);
                    tm_f.put(line[0], f - r);
                }
            }

            // Jetzt durchgehen und differenz in tm speichern
            for (String key : tm_r.keySet()) {
                double r = (double) (tm_r.get(key));
                double f = (double) (tm_f.get(key));
                tm.put(key, (r - f) / (r + f));
            }
            // Sortieren
            tm_o.putAll(tm);
            // Ausgeben
            for (String key : tm_o.keySet()) {
                out1.write(key + "\t " + tm.get(key) + "\n");
            }
            out1.flush();
            out1.close();

        } catch (IOException ex) {
            IOHelper.logError(ex);
        }


    }
}
